Inappropriate memory usage is an intractable class of computer programming errors. Analyzing and correcting such errors can be extremely difficult for a number of different reasons. For example, the source of the memory corruption and the manifestation of errors are usually far apart within the software (such as computer program code), making it difficult to correlate cause and effect. Additionally, symptoms appear under exceptional conditions, making it difficult to consistently reproduce the error. Among different types of memory usage errors, a very common and disastrous error is accessing memory through dangling pointers.
Dangling pointers are pointers to already freed memory blocks. Depending upon whether the memory block is in heap memory or stack memory, a dangling pointer is referred to as a heap dangling pointer or a stack dangling pointer. Heap memory allocation and deallocation is explicit, and is accomplished by calling heap memory management functions such as malloc( ) and free( ). Dereferencing a pointer after free( ) has been called for the heap memory block containing the memory pointed to by the pointer causes a heap dangling pointer.
Stack memory allocation and deallocation occurs when computer program control enters or exits from a function, such as a method. A stack dangling pointer occurs if a stack address escapes and becomes stored in a pointer that lives longer than the life of the function or method to which the stack address belongs. Since stack memory allocation is implicit, and the stack memory is reused upon entry into another function or method, detecting stack dangling pointers is relatively difficult.
Furthermore, memory leaks are heap memory blocks to which all pointers are lost, making it impossible for the computer program to free the memory block for subsequent reuse. A leak is characterized by an allocation site and a leak location. The allocation site is the line of a computer program at which the leaked heap memory block is initially allocated. The leak location is the line at which the last pointer to a given heap memory block is lost, resulting in the leak. Identification of the leak location in particular decreases debugging time considerably.
Currently available dangling pointer detection techniques mainly identify heap dangling pointers. Currently available memory leak detection techniques primarily identify the allocation sites for memory leaks, with a disadvantage of not being able to detect the actual leak locations. Such existing techniques to detect dangling pointers and leak locations suffer from other limitations as well. They may not free the heap memory for the purpose of detecting heap dangling pointers. They may be unusable without the source code for software, and/or be incapable of handling general C and C++ programming language applications. The existing approaches may require human intervention to make non-trivial source code modifications. These and other shortcomings of the prior art are addressed by the present invention.